<template>
  <div>
    <el-button type="primary" @click="showAdd = true">添加方案</el-button>
    <el-table :data="planList" style="width: 100%; margin-top: 20px;">
      <el-table-column prop="id" label="ID" width="60"/>
      <el-table-column prop="chronicName" label="慢病"/>
      <el-table-column prop="type" label="方案类型"/>
      <el-table-column prop="content" label="方案内容"/>
      <el-table-column prop="remindTime" label="提醒时间"/>
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button size="small" @click="editPlan(scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="deletePlan(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog v-model="showAdd" title="管理方案">
      <el-form :model="form">
        <el-form-item label="慢病"><el-input v-model="form.chronicName"/></el-form-item>
        <el-form-item label="方案类型"><el-input v-model="form.type"/></el-form-item>
        <el-form-item label="方案内容"><el-input v-model="form.content"/></el-form-item>
        <el-form-item label="提醒时间"><el-date-picker v-model="form.remindTime" type="datetime"/></el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="showAdd = false">取消</el-button>
        <el-button type="primary" @click="savePlan">保存</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref } from 'vue'
const planList = ref([])
const showAdd = ref(false)
const form = ref({})
const loadPlans = async () => { /* planList.value = await getPlanListApi() */ }
const savePlan = async () => {
  // if(form.value.id) await updatePlanApi(form.value)
  // else await addPlanApi(form.value)
  showAdd.value = false
  loadPlans()
}
const editPlan = (row) => { form.value = { ...row }; showAdd.value = true }
const deletePlan = async (id) => { /* await deletePlanApi(id); */ loadPlans() }
</script> 